<template>
  <!-- <div v-if="fielsStatus === 1"> -->
    <!-- <div class="activity-title-wrapper">
      <span class="activity-circle circle-red"></span>
      <span class="activity-title-text">冲刺排行榜&nbsp;&nbsp;&nbsp;&nbsp;快来拿大奖</span>
      <span class="activity-circle circle-red"></span>
    </div> -->
    <TeamRank :rankActivityList="rankActivityList" :fielsStatus="fielsStatus"/>
  <!-- </div> -->

</template>

<script>
import { activityRank } from '@/service/get-data.js'
import TeamRank from './teamRank'
export default {
  components: {
    TeamRank
  },
  data () {
    return {
      myRankData: {},
      rankActivityList: {},
      fielsStatus: 0
    }
  },
  computed: {
    userId () {
      return this.$store.state.user.id || undefined
    }
  },
  methods: {
    // 活动排名
    async fetchActivityRank () {
      let res = await activityRank(this.userId || undefined)
      if (res.data.resultCode && res.data.resultCode === 2000) {
        this.activity = res.data.data
        this.hanleTimer()
      } else {
        this.$message({
          message: res.data.resultMsg,
          type: 'wraming'
        })
      }
    },
    hanleTimer () {
      // 活动已结束
      if (this.activity.openRanks && !this.activity.openRanks.length) {
        this.rankActivityList = this.activity.overRanks[0]
        this.myRankData = this.rankActivityList['myRank']
        this.fielsStatus = 2
        return
      }
      this.rankActivityList = this.activity.openRanks[0] || {}
      this.myRankData = this.rankActivityList['myRank']
      // 样式
      let startTimeParm = this.rankActivityList.startTime
      let endTimeParm = this.rankActivityList.endTime
      const starTimeStamp = (new Date(startTimeParm.replace(/-/g, '/'))).getTime()
      const endTimeStamp = (new Date(endTimeParm.replace(/-/g, '/'))).getTime()
      let nowTime = (new Date()).getTime()
      // 活动开始
      if (nowTime > starTimeStamp && nowTime <= endTimeStamp) {
        this.fielsStatus = 1
      } else if (nowTime < starTimeStamp) {
        this.fielsStatus = 0
      }
    }
  },
  mounted () {
    this.fetchActivityRank()
  },
  watch: {
    fielsStatus (value) {
      this.$store.commit('RANKSTEP', value)
    }
  }
}
</script>

<style lang="scss" scoped>


</style>
